<template>
	<view >
		<MyInput 
			label="介绍" 
			v-model="descript" 
			:placeholder="dormitory.descript"/>
	</view>
</template>

<script setup>
	import { ref , watch , defineEmits} from "vue"
	
	import MyInput from '@/components/MyInput/MyInput.vue'
	
	import {DormitoryModel} from '@/service/model/dormitory.js'
	
	import {DormitoryState} from '@/enum/GlobalEnum.js'
	
	const props=defineProps({
		clickSubmitDescriptFlag:{
			type:Number
		},
		dormitory:{
			type:Object
		},
		dormitoryAllId:{
			type:Object
		}
	})
	
	const emits=defineEmits(['setDescriptOk'])
	
	watch(()=>props.clickSubmitDescriptFlag,()=>{
		submitDescript()
	})
	
	const descript = ref('')
	
	const dormitoryModel = new DormitoryModel()
	
	//提交修改名字
	const submitDescript=async()=>{
		
		if(!descript.value.trim()){
			uni.$emit('tips','请输入有效的介绍!','warn')
			return
		}
		
		const {data,success} = await dormitoryModel.patchSetDormitoryInfo({
			"dormitory_name" : props.dormitory.dormitory_name,
			"descript":descript.value,
			"type":DormitoryState.NORMAL
		},props.dormitoryAllId.dormitory_id)
		
		if(success){
			descript.value=''
			uni.$emit('tips',data,'success')
			emits('setDescriptOk')
		}
	}
</script>

<style lang="less">
	
</style>